package edu.calvin.djs32.cs214.interpreters.calculator.primitives;

import ovm.polyd.PolyD;
import edu.calvin.cs214.hobbes2008.HobbesTIR;
import edu.calvin.cs214.hobbes2008.IntegerTIR;
import edu.calvin.cs214.hobbes2008.StringTIR;
import edu.calvin.cs214.hobbes2008.TupleTIR;
import edu.calvin.djs32.cs214.interpreters.calculator.Primitive;

public class LessThanPrimitive implements Primitive, ILessThanPrimitive {

	public HobbesTIR apply(HobbesTIR... tir) {
		ILessThanPrimitive dispatcher = PolyD.build(ILessThanPrimitive.class, this);
		return dispatcher.lessThan(tir[0], tir[1]);
	}

	public HobbesTIR lessThan(IntegerTIR tir1, IntegerTIR tir2) {
		if (tir1.getInt() < tir2.getInt()){
			return new StringTIR("true");
		}else{
			return new TupleTIR();
		}
	}

	public HobbesTIR lessThan(StringTIR tir1, StringTIR tir2) {
		if (tir1.getString().compareTo(tir2.getString()) < 0){
			return new StringTIR("true");
		}else{
			return new TupleTIR();
		}
	}

	public HobbesTIR lessThan(HobbesTIR tir1, HobbesTIR tir2) {
		throw new IllegalStateException("unimplemented!");
	}

}
